using System;
using System.Diagnostics;
using Rhizome.Contract;
using Rhizome.Contract.Diag;

namespace Rhizome.Model
{
    public sealed class Logger : ILogger
    {
        public void WriteLine(string format, params object[] args)
        {
#if SILVERLIGHT || WINDOWS_PHONE
            Debug.WriteLine(string.Format(format, args), "Rhizome");
#else
            Trace.WriteLine(string.Format(format, args), "Rhizome");
#endif
        }

        public static RhizomeProperty<ILogger> LoggerProperty =
            RhizomeProperty<ILogger>.Register("Logger", true, 
#if DEBUG
			() => new Logger()
#else
			null
#endif
			);

#if !WINDOWS_PHONE
        
        public static void SetLogger(RhizomeElement target, ILogger value)
        {
            target.SetValue(LoggerProperty, value);
        }

        public static ILogger GetLogger(RhizomeElement target)
        {
            return target.GetValue(LoggerProperty);
        }
#endif
    }
}